package com.data.king.tenda;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.data.king.tenda.service.BackendService;
import com.data.king.tenda.service.TendaService;
import com.data.king.tenda.service.Util;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button startService;
    private Button stopService;
    private EditText textTendaUrl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        MyApplication application = (MyApplication)this.getApplicationContext();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        startService = (Button) findViewById(R.id.start_service);
        stopService = (Button) findViewById(R.id.stop_service);
        textTendaUrl = (EditText) findViewById(R.id.textDataUrl);
        startService.setOnClickListener(this);
        stopService.setOnClickListener(this);
        textTendaUrl.setText(application.getTENDA_URL());
    }

    @Override
    public void onClick(View v) {
        MyApplication application = (MyApplication)this.getApplicationContext();
        application.setTENDA_URL(textTendaUrl.getText().toString());
        switch (v.getId()) {
            case R.id.start_service:
                //Intent startIntent = new Intent(this, TendaService.class);
                Intent startIntent = new Intent(this, BackendService.class);
                startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startService(startIntent);
                break;
            case R.id.stop_service:
                Intent stopIntent = new Intent(this, BackendService.class);
                stopIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                stopService(stopIntent);
                break;
            default:
                break;
        }
    }
}
